package com.platform.metamodel;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.metamodel.schema.MutableColumn;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tommy
 * @create 2021/7/19 15:54
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MtTable {
    private String tableName;
    private String tableDesc;
    private String schema;
    private List<MtField> fields;
    private List<MutableColumn> mutableColumns;

    public MtTable(String tableName, String tableDesc, String schema){
        this.setTableName(tableName);
        this.setTableDesc(tableDesc);
        this.setSchema(schema);
        fields = new ArrayList<>();
        mutableColumns = new ArrayList<>();
    }

    public MtTable addField(MtField field){
        fields.add(field);
        mutableColumns.add(MtField.of(field));

        return this;
    }

    public List<MutableColumn> getColumns(){
        List<MutableColumn> mutableColumns = new ArrayList<>();
        fields.forEach( field -> {
            mutableColumns.add(MtField.of(field));
        });

        return mutableColumns;
    }
}
